package dao

import (
	"context"
	"device-admin/internal/dal"
	"device-admin/internal/models"
	"time"
)

type WebshellLog struct{}

// Add 新增日志
func (WebshellLog) Add(ctx context.Context, query *dal.Query, record models.WebshellLog) (string, error) {
	wl := query.WebshellLog
	err := wl.WithContext(ctx).Create(&record)
	return record.ID, err
}

// DeleteExpired 删除过期的记录
func (WebshellLog) DeleteExpired(ctx context.Context, query *dal.Query, expiredTime int64) error {
	wl := query.WebshellLog
	wl.WithContext(ctx).Where(wl.CreatedAt.Lt(time.Now().Unix() - expiredTime)).Delete(&models.WebshellLog{})
	return nil
}
